package cn.base.web.auth;


import cn.base.web.cahe.SessionExpiry;
import cn.base.web.config.LoginProperties;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 单体服务使用内存缓存，see LocalTemporaryCache
 */
@Configuration
public class SessionCacheConfiguration {
	@Autowired
	private LoginProperties loginProperties;

	@Bean("sessionCache")
	public CaffeineCache sessionCache() {
		CaffeineCache caffeineCache=new CaffeineCache("session",
				Caffeine.newBuilder().expireAfter(new SessionExpiry(loginProperties.getTokenTimeout())).build(),
				false);//不允许空值
		return caffeineCache;
	}

}
